package com.wqh.zeromq;

import com.baosight.hdsdk.HDDataProvider;
import com.baosight.hdsdk.HDTagManager;
import com.baosight.hdsdk.domain.data.HDBasicTag;
import com.baosight.hdsdk.domain.data.HDDataConnection;
import com.baosight.hdsdk.exception.HDSdkException;
import com.wqh.zeromq.util.HDManager;
import org.json.JSONObject;
import java.util.*;

public class Test {
    public static void main(String[] args) {
        testRegister();
    }

    public static void testMap() {
        List<String> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();

        String str= "app_C-page_19-[{\"alias_11400\":8883,\"alias_11401\":8883}]";
        String str2= "app_D-page_20-[{\"alias_11400\":8800,\"alias_11402\":8890}]";
        list.add(str);
        list.add(str2);

        for(String message:list){
            String messageName = message.substring(0,message.indexOf("[")-1);
            String messageValue = message.substring(message.indexOf("[")+1,message.length()-1);
            //System.out.println(messageValue);
            JSONObject jsonObject =new JSONObject(messageValue);

            Map<String, Object> newMap = jsonObject.toMap();

            for(String key : newMap.keySet()){
                map.put(key,newMap.get(key));
            }
        }
        System.out.println(map);

        JSONObject jsonObject=new JSONObject(map);
        System.out.println(jsonObject.toString());
    }

    public static void testRegister() {
        HDDataConnection connection = HDManager.getConnection();
        HDTagManager manager = connection.getTagManager();
        HDDataProvider provider = new HDDataProvider(connection);
        HDBasicTag tag = null;
        String tagName="WuQiHang_basicTag_records";

        try {
            tag = manager.getBasicTagByName(tagName);
            List<Integer> list = new ArrayList<>();
            list.add(tag.getId());
            provider.register_callback(list);
        } catch (HDSdkException e) {
            e.printStackTrace();
        }

    }
}
